package com.ki.erp.pl;

import com.ki.erp.constant.MongoStaticQueryConstant;
import com.ki.erp.util.JsonToAggregationConverter;
import jakarta.annotation.Resource;
import org.bson.Document;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ProductPl {
    @Resource
    private MongoTemplate orderTemplate;

    public List<Document> temp() throws Exception {

        AggregationResults<Document> product = orderTemplate.aggregate(Aggregation.newAggregation(JsonToAggregationConverter.convert(MongoStaticQueryConstant.INSURANCE_ON_SALE)),
                "product",
                Document.class
        );
        return product.getMappedResults();
    }
}
